<?php
class OrderStatisticsAction  extends CommonAction{
   public function Index()
   {
       if($_REQUEST['do']=="search"){
           $sql_str ="SELECT * FROM ".C("DB_PREFIX")."order WHERE money_status=2 ";
           if(!empty($_REQUEST["begintime"])&&!empty($_REQUEST["endtime"]))
            {
                    $sql_str .= " and create_time between ".localStrToTime($_REQUEST["begintime"])." and ".localStrToTime($_REQUEST["endtime"]);
                    $this->assign('begintime',$_REQUEST["begintime"]);
                    $this->assign('endtime',$_REQUEST["endtime"]);
            }
            elseif(!empty($_REQUEST["begintime"]))
            {
                    $sql_str .= " and create_time >= ".localStrToTime($_REQUEST["begintime"]);
                    $this->assign('begintime',$_REQUEST["begintime"]);
            }
            elseif(!empty($_REQUEST["endtime"]))
            {
                    $sql_str .= " and create_time <= ".localStrToTime($_REQUEST["endtime"]);
                    $this->assign('endtime',$_REQUEST["endtime"]);
            }
            
           $sql_str .=" order by create_time desc";
           $list = M()->query($sql_str);
           foreach($list as $k =>$v){
	            $list[$k]['goods_list'] = M()->query("SELECT og.*,g.* FROM ".C("DB_PREFIX")."order_goods og LEFT JOIN ".C("DB_PREFIX")."goods g ON og.rec_id=g.id WHERE og.order_id={$v['id']} ");
			   foreach($list[$k]['goods_list'] as $kk => $vv)
			   {
				   $list[$k]['goods_list'][$kk]['profitnow'] = $vv['shop_price'] - $vv['profit'];
			   }
           }
            $this->assign ( 'list', $list );
       }
       $this->display();
   }
}
?>
